package cn.highset.modules.base.controller.api;

import cn.highset.base.ApiBaseController;
import cn.highset.common.annotation.IgnoreAuth;
import cn.highset.common.utils.ResultUtil;
import cn.highset.common.vo.Result;
import cn.highset.modules.base.entity.ProductType;
import cn.highset.modules.base.service.ProductTypeService;
import cn.hutool.core.collection.CollUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类 描 述：API 小程序产品类别信息
 * 创建时间：2019-06-15 10:32
 * 创 建 人：victor
 */
@Slf4j
@RestController
@Api(description = "API产品类别信息")
@RequestMapping("/api/productType")
@Transactional
public class ApiProductTypeController extends ApiBaseController {

    @Autowired
    private ProductTypeService productTypeService;


    /**
     * @name: 获取产品类别列表
     * @description: TODO
     * @return:
     * @date: 2019-06-15 10:41
     * @auther: victor
     */
    @ApiOperation(value = "获取产品类别列表")
    @IgnoreAuth
    @PostMapping("list")
    public Result<Object> list() {
        List<ProductType> list = productTypeService.findByParentIdOrderBySortOrder("0");
        if (CollUtil.isNotEmpty(list)) {
            for (ProductType parent : list) {
                parent.setChildren(productTypeService.findByParentIdOrderBySortOrder(parent.getId()));
            }
        }
        return new ResultUtil<Object>().setData(list);
    }

}
